import {createRouter, createWebHashHistory, RouteRecordRaw} from "vue-router";


const routes:Array<RouteRecordRaw> = [
    {
        path: "/",
        component: ()=>import('../views/home/Home.vue')
    },
    {
        path: '/articles/:articleId',
        component: ()=> import('../views/article/Article.vue')
    },
    {
        path: '/archives',
        component: ()=> import('../views/archive/Archive.vue'),
        meta: {
            title: '归档'
        }
    },
    {
        path: '/albums',
        component: ()=> import('../views/albums/Album.vue'),
        meta: {
            title: '相册'
        }
    },
    {
        path: '/albums/:albumId',
        component: ()=> import('../views/albums/Photo.vue'),
    },
    {
        path: '/tags',
        component: ()=> import('../views/tag/Tag.vue'),
        meta: {
            title: '标签'
        }
    },
    {
        path: '/categories',
        component: ()=> import('../views/category/Category.vue'),
        meta: {
            title: '分类'
        }
    },
    {
        path: '/categories/:categoryId',
        component: ()=> import('../views/category/Category.vue'),
    },
    {
        path: '/tags/:tagId',
        component: ()=> import('../views/article/ArticlesList.vue'),
    },
    {
        path: '/links',
        component: ()=> import('../views/link/Link.vue'),
        meta: {
            title: '友链列表'
        }
    },
    {
        path: '/about',
        component: ()=> import('../views/about/About.vue'),
        meta: {
            title: '关于我'
        }
    },
    {
        path: '/message',
        component: ()=> import('../views/message/Message.vue'),
        meta: {
            title: '留言板'
        }
    },

]


const router = createRouter({
    history: createWebHashHistory(),
    routes: routes,
    scrollBehavior(to, from, savedPosition) {
        // 如果有保存的位置（比如浏览器前进/后退），则恢复到保存的位置
        if (savedPosition) {
            return savedPosition;
        }
        // 否则滚动到页面顶部
        return { top: 0, behavior: 'smooth' };
    }
})

export default router
